home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dtksh / DtWsTest1.z / DtWsTest1
Encoding:
Text File  |  2003-11-18  |  6.2 KB  |  179 lines

  1. #! /usr/dt/bin/dtksh
  2. #
  3. # DtWsTest1
  4. #
  5. # Copyright 2000, Silicon Graphics, Inc.
  6. # ALL RIGHTS RESERVED
  7. # UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8. # States.   Use of a copyright notice is precautionary only and does not
  9. # imply publication or disclosure.
  10. #
  11. # U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14. # in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15. # in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16. # Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17. # 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18. #
  19. # THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20. # INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21. # DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22. # PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23. # GRAPHICS, INC.
  24. #
  25.  
  26. ##########################################################################
  27. #  (c) Copyright 1993, 1994 Hewlett-Packard Company    
  28. #  (c) Copyright 1993, 1994 International Business Machines Corp.
  29. #  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  30. #  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
  31. #      Novell, Inc.
  32. ##########################################################################
  33.  
  34.  
  35. #
  36. # This sample shell script demonstrates how to interact with the workspace
  37. # manager.  It demonstrates the following capabilities:
  38. #
  39. #    1) How to query which workspaces the widgets currently reside it.
  40. #    2) How to set the current workspace.
  41. #    3) How to be notified when the current workspace changes.
  42. #
  43.  
  44.  
  45. integer wsCount
  46.  
  47. # Pushbutton Callback: This function asks the workspace manager to change
  48. #                      to the workspace indicated by $1; $1 is an X atom
  49. #                      which identifies the new workspace.  At some point
  50. #                      after our request to the workspace manager, the
  51. #                      workspace manager will activate our WsCB function,
  52. #                      letting us know that the change has actually taken
  53. #                      place.
  54. SetWorkspace()
  55. {
  56.    echo
  57.    if DtWsmSetCurrentWorkspace $TOPLEVEL $1; then
  58.       echo "Changing to new workspace"
  59.    else
  60.       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $1
  61.       echo "Unable to Change to workspace " $NAME
  62.    fi
  63. }
  64.  
  65. # Workspace Changed Callback: This function is invoked whenever the workspace
  66. #                             manager changes workspaces.  It will simply
  67. #                             query the 'name' of the new workspace, and
  68. #                             echo it outl
  69. WsCB()
  70. {
  71.    DtWsmGetCurrentWorkspace $(XtDisplay "-" $TOPLEVEL) \
  72.                        $(XRootWindowOfScreen "-" $(XtScreen "-" $TOPLEVEL)) \
  73.                        NEW_ATOM
  74.    XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $NEW_ATOM
  75.    echo "Change to workspace complete " $NAME  "("$NEW_ATOM")"
  76. }
  77.  
  78. ######################### Create the Main UI #################################
  79.  
  80. XtInitialize TOPLEVEL dtWsTest DtWsTest "$0" "$@"
  81. XtSetValues $TOPLEVEL allowShellResize:True
  82.  
  83. XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
  84. XtSetValues $DA height:200 width:200
  85.  
  86. XtRealizeWidget $TOPLEVEL
  87. XSync $(XtDisplay "-" $TOPLEVEL) False
  88.  
  89. XtCreateApplicationShell TOPLEVEL2 DtWsTesta TopLevelShell
  90.  
  91. XtCreateManagedWidget RC rc XmRowColumn $TOPLEVEL2 \
  92.          orientation:HORIZONTAL \
  93.          packing:PACK_COLUMN 
  94.  
  95. # Get a list of all of the workspaces, and create a pushbutton for each one.
  96. # When a pushbutton is activated, it will ask the workspace manager to
  97. # change to the indicated workspace.
  98. oldIF=$IFS
  99. if DtWsmGetWorkspaceList $(XtDisplay "-" $TOPLEVEL) \
  100.                           $(XRootWindowOfScreen "-" $(XtScreen "-" $TOPLEVEL)) \
  101.                           WS_LIST; 
  102. then
  103.    IFS=,
  104.    wsCount=0
  105.    for item in $WS_LIST; 
  106.    do
  107.       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
  108.       label="Set Current Workspace to "$NAME
  109.       XtCreateManagedWidget ITEM $item XmPushButton $RC \
  110.          labelString:$label
  111.       XtAddCallback $ITEM activateCallback "SetWorkspace $item"
  112.       wsCount=$wsCount+1
  113.    done
  114.    IFS=$oldIFS
  115. else
  116.    echo "Unable to get workspace list"
  117.    exit -1
  118. fi
  119.  
  120. XtSetValues $RC numColumns:$wsCount
  121. XtRealizeWidget $TOPLEVEL2
  122. XSync $(XtDisplay "-" $TOPLEVEL) False
  123.  
  124. # The following block queries the initial set of workspaces occupied by
  125. # this shell script; this list is printed out.  Next, it will ask the
  126. # workspace manager to move the shell script windows into all workspaces.
  127. # Lastly, it will again ask the workspace manager for the list of
  128. # workspaces occupied by the shell script windows, and will again print
  129. # out the list.
  130. if DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
  131.                                $(XtWindow "-" $TOPLEVEL) \
  132.                                CURRENT_WS_LIST ;
  133. then
  134.    echo "Initial workspaces occupied:"
  135.    for item in $CURRENT_WS_LIST; 
  136.    do
  137.       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
  138.       echo "   "$NAME
  139.    done
  140.  
  141.    DtWsmGetWorkspaceList $(XtDisplay "-" $TOPLEVEL) \
  142.                           $(XRootWindowOfScreen "-" $(XtScreen "-" $TOPLEVEL)) \
  143.                           WS_LIST
  144.  
  145.    DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
  146.                                $(XtWindow "-" $TOPLEVEL) \
  147.                                $WS_LIST
  148.  
  149.    DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL2) \
  150.                                $(XtWindow "-" $TOPLEVEL2) \
  151.                                $WS_LIST
  152. else
  153.    echo "Unable to get current list of occupied workspaces"
  154.    echo -2
  155. fi
  156.  
  157. XSync $(XtDisplay "-" $TOPLEVEL) False
  158.  
  159. # Print the new list of workspaces occupied
  160. DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
  161.                             $(XtWindow "-" $TOPLEVEL) \
  162.                             CURRENT_WS_LIST
  163.  
  164. echo "After modification, workspaces occupied:"
  165. IFS=,
  166. for item in $CURRENT_WS_LIST; 
  167. do
  168.    XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
  169.    echo "   "$NAME
  170. done
  171. IFS=$oldIFS
  172. echo ""
  173.  
  174. # Add a callback to be notified whenever the workspace changes.
  175. DtWsmAddCurrentWorkspaceCallback HANDLE1 $TOPLEVEL WsCB
  176.  
  177. XtMainLoop
  178.